<!DOCTYPE html>
<html>
	<head>
		<head>
			<title>基本资料</title>
			<meta name="renderer" content="webkit">
			<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
			<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
			<link rel="stylesheet" href="../../css/layui.css" media="all">
			<link rel="stylesheet" href="../../style/admin.css" media="all">
		</head>
	</head>
	<body>

		<div id="userInfo" style="margin-top: 2rem;text-align: center;padding: 0 28rem;">
			<div class="layui-form-item">
				<img :src="avatar" style="border-radius: 50%;width: 5rem;height: 5rem;" />
			</div>

			<div class="layui-form-item">
				id:
				{{suid}}
			</div>
			<div class="layui-form-item">
				用户名:
				{{name}}
			</div>
			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
				角色：{{role_name}}
			</div>
			<button class="layui-btn layui-btn-fluid updatePwd">修改密码</button>

		</div>

		<div class="layui-fluid addPanel" style="display: none;margin-top: 20px;">
			<form class="layui-form layui-form-pane addForm" lay-filter="addForm">
				<div class="layui-form-item">
					<label class="layui-form-label">旧密码</label>
					<div class="layui-input-block">
						<input type="password" name="oldPwd" autocomplete="off" placeholder="请输入旧密码" class="layui-input popupinput">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-block">
						<input type="password" name="newPwd" autocomplete="off" placeholder="请输入新密码" class="layui-input popupinput">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认密码</label>
					<div class="layui-input-block">
						<input type="password" name="renewPwd" autocomplete="off" placeholder="请再次输入新密码" class="layui-input popupinput">
					</div>
				</div>
			</form>
		</div>

		<script src="../../plugins/vue/vue.min.js"></script>
		<script src="../../js/user/userInfo.js"></script>
		<script src="../../layui.js"></script>
		<script src="../../plugins/jquery/jquery.min.js"></script>
		<script src="../../js/utils/common.js"></script>
		<script src="../../js/utils/interceptor.js"></script>
		<script src="../../js/utils/md5.js"></script>

		<script>
			var suid = localStorage.getItem('suid');
			var oldpassword1 = localStorage.getItem('password');
			layui.use(['form', 'layer'], function() {
				var layer = layui.layer;
				var form = layui.form;
				//自定义验证规则


				$('.updatePwd').on('click', function() {
					var url = GlobalSiteUrl + "/admin/updateManageInfoBySuid";
					console.log(url)
					layer.open({
						area: ['400px', '330px'],
						type: 1,
						title: '修改密码',
						content: $('.addPanel'),
						btn: ['确定', '取消'],
						yes: function(index) {
							var data = $('.addForm').serializeArray();
							console.log(data)
							var oldPwd = data[0].value
							var newPwd = data[1].value
							var renewPwd = data[2].value
							var oldpassword2 = $.md5(oldPwd)
							var password = $.md5(newPwd)
							if (oldpassword1 !== oldpassword2) {
								layer.msg("旧密码错误", {
									anim: 6,
									time:1000
								});
								return 0
							} else if (oldPwd == '') {
								layer.msg("请填写旧密码", {
									anim: 6,
									time:1000
								});
								return 0
							} else if (newPwd == '') {
								layer.msg("请填写新密码", {
									anim: 6,
									time:1000
								});
								return 0
							} else if (renewPwd == '') {
								layer.msg("请再次填写新密码", {
									anim: 6,
									time:1000
								});
								return 0
							} else if (newPwd != renewPwd) {
								layer.msg("两次输入的密码不准确", {
									anim: 6,
									time:1000
								});
								return 0
							} else if (oldPwd == newPwd) {
								layer.msg("新密码和旧密码相同", {
									anim: 6,
									time:1000
								});
								return 0
							}
							$.post({
								url: url,
								data: {
									suid: suid,
									password: password
								},
								success: function(res) {
									localStorage.setItem("password", password)
									console.log(res);
									if (res.status == 200) {
										layer.msg(res.msg);
										layer.close(index);
										setTimeout(function() {
											location.reload();
										}, 1000);
									} else {
										layer.msg(res.msg, {
											time: 1500,
											anim: 6
										});
										layer.close(index);
									}
								}
							});
						}
					});
				});
			});
		</script>






	</body>
</html>
